#include "Application.h"
#include "GameObject.h"
#include "Factory.h"
 
TutorialApplication::TutorialApplication(void)
{
}
 
TutorialApplication::~TutorialApplication(void)
{
}
 
//-------------------------------------------------------------------------------------
void TutorialApplication::createScene(void)
{
    // Set the scene's ambient light
    mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5f, 0.5f, 0.5f));
 
    //// Create an Entity
    //Ogre::Entity* ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh");
 
    //// Create a SceneNode and attach the Entity to it
    //Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("HeadNode");
    //headNode->attachObject(ogreHead);
 
    // Create a Light and set its position
    Ogre::Light* light = mSceneMgr->createLight("MainLight");
    light->setPosition(20.0f, 80.0f, 50.0f);

	//////
	// Initialize meta-tables
	Factory::registerMetatables();

	/////////////////
	// Create world
	/////////////////
	Ogre::Plane plane(Ogre::Vector3::UNIT_Y, 0);
	Ogre::MeshManager::getSingleton().createPlane("ground", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		plane, 1500, 1500, 20, 20, true, 1, 5, 5, Ogre::Vector3::UNIT_Z);
	Ogre::Entity* entGround = mSceneMgr->createEntity("GroundEntity", "ground");
	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entGround);

	Factory::createTree(1, 1);
	Factory::createTree(0, 0);
	Factory::createTree(0, 1);
	Factory::createUnit(1, 0);
}

void TutorialApplication::onFrame()
{
	GameObject::updateAll();
}

#include "Pathfinding/Map.h"
#include "IntGeometry.h"


 void createMap()
 {
	 static const char* mapSource = 
"\
00000000000000000000\
01111110000000000000\
01000010000000000000\
01000000000000000000\
01000001111111000000\
01111111000001000000\
00000000011101000000\
00111000011101000000\
00100000011101000010\
00100000000000000010\
00100000010000000010\
00100000000000000010\
00111111111111111110\
00000000000000000000\
00000000000000000000\
00000000000000000000\
00000000000000000000\
00000000000000000000\
00000000000000000000\
00000000000000000000";
	 pathfinding::Map map;
	 map.setRect(IntRect(-10, -10, 20, 20));
 }
 
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#endif
 
#ifdef __cplusplus
extern "C" {
#endif
 
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
    int WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
    int main(int argc, char *argv[])
#endif
    {
        // Create application object
        TutorialApplication app;
 
        try 
        {
            app.go();
        } catch( Ogre::Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
            MessageBoxA( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR| MB_TASKMODAL);
#else
            std::cerr << "An exception has occured: " << e.getFullDescription().c_str() << std::endl;
#endif
        }
 
        return 0;
    }
 
#ifdef __cplusplus
}
#endif